<?php
/**
 * 工单
 */
namespace app\manage\controller\consult;

use app\manage\controller\Base;

class Api extends Base
{
	/**
	 * 未完结工单
	 * @return [type] [description]
	 */
	public function ing(){
		$params = $this->request->param();
        
        $perpagenum = isset($params['limit'])?intval($params['limit']):15;
        $perpagenum = $perpagenum>100?100:$perpagenum;
        $page = isset($params['page'])?intval($params['page']):1;
        $page = $page<1?1:$page;

        unset($params['limit']);
        unset($params['page']);
        $where = [];
        if(isset($params['key'])){
            $where= parseWhere($params['key']);
        }
        $where['pid'] = 0;
		$where['isover'] = 0;

        $data = model('consult')->getPageDatas($where,$page,$perpagenum);
        $data['code'] = 1;
        return json($data);
	}
	/**
	 * 已完结工单
	 * @return [type] [description]
	 */
	public function over(){
		$params = $this->request->param();
        
        $perpagenum = isset($params['limit'])?intval($params['limit']):15;
        $perpagenum = $perpagenum>100?100:$perpagenum;
        $page = isset($params['page'])?intval($params['page']):1;
        $page = $page<1?1:$page;

        unset($params['limit']);
        unset($params['page']);
        $where = [];
        $where['pid'] = 0;
		$where['isover'] = 1;
        if(isset($params['key'])){
            $where= parseWhere($params['key']);
        }

        $data = model('consult')->getPageDatas($where,$page,$perpagenum);
        $data['code'] = 1;
        return json($data);
	}

	public function row(){
		$params = $this->request->param();
		$id = isset($params['id'])?$params['id']:0;

		$data = model('consult')->getOneSubject($id);
		return json($data);
	}



	// /**
	//  * 未完结工单
	//  * @return [type] [description]
	//  */
	// public function ing(){
	// 	$params = $this->request->param();

	// 	$where = $params;
	// 	unset($where['page']);
	// 	$where['pid'] = 0;
	// 	$where['isover'] = 0;
	// 	unset($where['page']);
	// 	$queryStr = $where?'&'.parseQuery($where):'';

	// 	$query = new \app\common\query\Consult;
	// 	$data = $query->getRows($where,$queryStr,url('consult.show/ing'));

	// 	return json($data);

	// }

	// public function over(){
	// 	$params = $this->request->param();

	// 	$where = $params;
	// 	unset($where['page']);
	// 	$where['pid'] = 0;
	// 	$where['isover'] = 1;
	// 	$queryStr = $where?'&'.parseQuery($where):'';

	// 	$query = new \app\common\query\Consult;
	// 	$data = $query->getRows($where,$queryStr,url('consult.show/over'));

	// 	return json($data);
	// }

	
}